.org 0xE646C ; Firepower Increase

Firepower_Increase:

	PUSH 	{R4-R7, LR}
	
	SUB 	SP, SP, 4
	
	LDR 	R4, [Firepower_Increase_1]
	LDR 	R3, [Firepower_Increase_2]
	LDR 	R5, [R4, 0]
	LDR 	R4, [R3, 0]
	MOV 	R3, 0x98
	ADD 	R4, R5, R4, LSL 2
	MUL		R5, R0, R3
	LDR 	R4, [R4, 0x48]
	MOV		R7, R2
	ADD 	R0, R4, 0x5000
	LDR 	R0, [R0, 0xA58]
	MOV		R4, R1, LSL 4
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R1, LSL 4
	
	MOV 	R1, CO_Teamwork						; Skill: Teamwork
	
	MOV		R6, 0
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, CO_Synergy						; Skill: Synergy
	
	ADD		R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	
	ADDNE 	R6, R6, 5							; If CO use skill, Partner has +5 firepower	
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]

	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	MOV		R0, R7
	
	ADDNE 	R6, R6, 8							; If CO use skill, Partner has +8 firepower	
	
;-------------------------------------------------------------------------------	
	
	BL 		Check_Unit_Type
	
	CMP		R0, Unit_Direct_Combat				; Is Unit a Direct?
	BEQ		Skill_Firepower_Direct
	
	CMP		R0, Unit_Indirect_Combat			; Is Unit an Indirect?
	BEQ		Skill_Firepower_Indirect
	
	B		Skill_Firepower_Weather

;-------------------------------------------------------------------------------	

Skill_Firepower_Direct:

	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, Rank_Bruiser					; Rank: Bruiser
	
	ADD		R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADDNE 	R6, R6, 5							; If CO use skill, +5 Direct firepower	
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	MOV 	R1, Rank_Brawler					; Rank: Brawler
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, 8							; If CO use skill, +8 Direct firepower	
	
	B		Skill_Firepower_Weather

;-------------------------------------------------------------------------------	

Skill_Firepower_Indirect:

	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, Rank_Sharpshooter				; Rank: Sharpshooter
	
	ADD		R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV 	R1, Rank_Sniper						; Rank: Sniper
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE 	R6, R6, 5							; If CO use skill, +5 Indirect firepower	
		
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, 8							; If CO use skill, +8 Indirect firepower	
	
;-------------------------------------------------------------------------------

Skill_Firepower_Weather:
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R1, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADD		R0, R1, R0, LSL 2
	LDR		R1, [R0, 0x48]	
	LDR		R0, [R1, 0x1C4]
	LDRB	R0, [R0, 0x3A]
	
	CMP		R0, Snow
	BEQ		Skill_Firepower_Snow				; Is weather snow?
	
	CMP		R0, Rain
	BEQ		Skill_Firepower_Rain				; Is weather rain?
	
	CMP		R0, Sandstorms
	BEQ		Skill_Firepower_Sand				; Is weather sandstorms?
	
	B		Skill_Firepower_Clear				

;-------------------------------------------------------------------------------	

Skill_Firepower_Snow:

	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]
	
	MOV 	R1, Rank_Icebreaker					; Rank: Icebreaker
	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADDNE 	R6, R6, 20							; If CO use skill, +20 firepower
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	MOV 	R1, CO_Firepower_Snow				; Skill: Firepower in Snow
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, 20							; If CO use skill, +20 firepower
	
	B		Skill_Firepower_Clear

;-------------------------------------------------------------------------------	

Skill_Firepower_Rain:

	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]
	
	MOV 	R1, Rank_High_and_Dry				; Rank: High and Dry
	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, 20							; If CO use skill, +20 firepower
	
	B		Skill_Firepower_Clear

;-------------------------------------------------------------------------------	

Skill_Firepower_Sand:

	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]
	
	MOV 	R1, Rank_Sand_Scorpion				; Rank: Sand Scorpion
	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, 20							; If CO use skill, +20 firepower

;-------------------------------------------------------------------------------

Skill_Firepower_Clear:
	
	MOV		R0, R6
	ADD		SP, SP, 4
	
	POP 	{R4-R7, LR}
	
	BX 		LR

;-------------------------------------------------------------------------------		

Firepower_Increase_1:
	.dw Reg1_Skill
	
Firepower_Increase_2:
	.dw Reg2_Skill



